<?php
namespace app\index\model;
use think\Db;
/**
 * Created by Submint Text.
 * User: hetaoren<452649510@qq.com>
 * Date: 2017/03/10
 * Explain: 客户分类业务处理
 */
class Classify extends Base{
	/**
	 * 获取
	 */
	public function pageQuery(){
		return $this->where('dataFlag',1)->order('classifySort asc, classifyId asc')->paginate(input('post.pagesize/d'))->toArray();
	}
	/**
	 * 获取列表
	 */
	public function listQuery(){
		return $this->where('dataFlag',1)->order('classifySort asc, classifyId asc')->column('classifyId','classifyName');
	}
	 	
	/**
	 * 新增
	 */
	public function add(){
		$data = input('post.');
		HTRUnset($data,'classifyId');
		$result = $this->insert($data);
		if(false !== $result){
			return HTRReturn("新增成功", 1);
		}else{
			return HTRReturn($this->getError());
		}
	}
	
	/**
	 * 编辑
	 */
	public function edit(){
		$classifyId = input('post.classifyId/d');
		$data = input('post.');
		$result = $this->allowField(true)->save($data,['classifyId'=>$classifyId]);
		if(false !== $result){
			return HTRReturn("修改成功", 1);
		}else{
			return HTRReturn($this->getError());
		}
	}
	
	/**
	 * 删除
	 */
	public function del(){
		$classifyId = input('post.id/d');
		$data = [];
		$data['dataFlag'] = -1;
		$result = $this->update($data,['classifyId'=>$classifyId]);
		if($result){
			return HTRReturn("删除成功", 1);
		}else{
            return HTRReturn('删除失败');
        }
	}
}